package com.sunshine.student_register.database.student;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

/**
 * @author sunshine
 * @date 2020/5/30
 * 学生表的操作接口
 */

@Dao
public interface StudentDao {

    //查找全部
    @Query("SELECT * FROM StudentEntity")
    List<StudentEntity> getAllStudent();

    //通过id查找学生
    @Query("SELECT * FROM StudentEntity WHERE id=:id")
    StudentEntity getStudent(int id);

    //插入
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertStudent(StudentEntity studentEntity);

    //修改
    @Update
    void updateStudent(StudentEntity studentEntity);

    //删除
    @Delete
    void deleteStudent(StudentEntity studentEntity);

    //删除全部
    @Query("DELETE FROM StudentEntity WHERE 1=1")
    void deleteAllStudent();
}
